import 'package:new_yuqib_app/yqbModel/im_login_data_model.dart';
import 'package:new_yuqib_app/yqbNetwork/api_metholds.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
import 'package:tencent_cloud_chat_uikit/ui/controller/tim_uikit_chat_controller.dart';

///腾讯Im相关
class TencentImUtils {
  TencentImUtils._();

  static final _coreInstance = TIMUIKitCore.getInstance();

  ///初始化
  static init() {
    _coreInstance.init(sdkAppID: 1400702447, loglevel: LogLevelEnum.V2TIM_LOG_DEBUG, listener: V2TimSDKListener());
  }

  ///会话界面控制器
  static final messageController = TIMUIKitChatController();

  ///登录
  static login(ImLoginDataModel data) {
    _coreInstance.login(userID: data.userId, userSig: data.sig);
  }

  static imLogin() {
    ApiMethods.imChatGetSig().then((value) {
      TencentImUtils.login(value);
    });
  }

  ///删除会话信息
  static Future deleteConversion(String serviceId) async {
//清空单聊本地及云端的消息（不删除会话）
    await TencentImSDKPlugin.v2TIMManager.getMessageManager().clearC2CHistoryMessage(userID: serviceId); // 需要清空记录的用户id
    //删除会话
    await TencentImSDKPlugin.v2TIMManager.getConversationManager().deleteConversation(conversationID: serviceId //需要删除的会话id
        );
    messageController.clearHistory(serviceId);
    // await TencentImSDKPlugin.v2TIMManager.getMessageManager().clearC2CHistoryMessage(userID: "c2c_$serviceId"); // 需要清空记录的用户id
    // //删除会话
    // await TencentImSDKPlugin.v2TIMManager.getConversationManager().deleteConversation(conversationID: "c2c_$serviceId"); //需要删除的会话id

  }
}
